/**
* Javascipt Library for editor
* @Ray Li
* dependency
* <script type="text/javascript" src="js/components/texteditor/fckeditor.js"></script>
*/

  function Editor(editorName){
      this.TYPE_ADVANCED = "Advanced";
      this.TYPE_PLAIN = "Plain"
      this.editorBasePath = "/hr/js/components/texteditor/";
      this.editorSkinPath = this.editorBasePath + "editor/skins/office2003/";
      if(editorName) this.editorName = editorName;
      
      /**replace the textarea with editor widget
      * usage: <textarea name="content" rows="10" cols="80" height=500 editor="true" editortype="Advanced"></textarea>
      * textarea attribute: 
      * editor: {true|false} enable editor replacement
      * height: {value} height of editor widget
      * editortype:{Advanced|Plain|Basic} set toolbar Sets for editor widget
      */
      this.autoReplaceTextarea = function(){
          var objs = document.getElementsByTagName("TEXTAREA");
          for(var i=0; i<objs.length; i++){
              if(objs[i].editor == "true"){
                  var oFCKeditor = new FCKeditor( objs[i].name );
                  oFCKeditor.BasePath	= this.editorBasePath ;
                  oFCKeditor.Config['SkinPath'] = this.editorSkinPath ;
                  if(objs[i].editortype){
                      oFCKeditor.ToolbarSet = objs[i].editortype;  
                  }else{
                      oFCKeditor.ToolbarSet = this.TYPE_PLAIN;    
                  }  
                  
                  if(objs[i].height){
                      oFCKeditor.Height	= objs[i].height;
                  }else{
                      oFCKeditor.Height	= 300;
                  }
                  
                  oFCKeditor.ReplaceTextarea();
              }      
          }
      }
      
      this.getContent = function(editorName){
          if(editorName){
   	          var oEditor = FCKeditorAPI.GetInstance(editorName) ;

	          // Get the editor contents in XHTML.
	          return oEditor.GetXHTML( true );		// "true" means you want it formatted.    
          }else{
              return "";
          }
      }
  
  }
  
    var textEditor = new Editor();